package com.hlbbcsr.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.hlbbcsr.dao.ContractDAO;
import com.hlbbcsr.domain.bean.Contract;

@Repository("contractDAO")
public class ContractDAOImpl extends BaseHelperDAO implements ContractDAO{

	@Override
	public List<Contract> listContract() throws Exception {
		// list all Contract
		List<Contract> result = new ArrayList<Contract>();
		
		String queryString = "from Contract";
		Query query = getCurrentSession().createQuery(queryString);
		result = query.list();
		System.out.println(result.size()+"step 1");
		return result;
	}

	public void addContract(Contract entity) throws Exception {
		// Add new contract into Database
		getCurrentSession().save(entity);
		
	}

	@Override
	public List<Contract> searchEngine(Contract entity) throws Exception {
		// list contract where condition
		List<Contract> result = new ArrayList<Contract>();
		
		String queryString = "from Contract where contract_Name LIKE :name";
		Query query = getCurrentSession().createQuery(queryString).setParameter("name", "%"+entity.getContractName().toString()+"%");
		 
		result = query.list();
		System.out.println(result.size()+"step 1");
		return result;
		
	} 
}
